package cn.dmw.jedis;

import org.junit.jupiter.api.Test;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.util.HashSet;
import java.util.Set;

public class JedisTest {

    /**
     * 测试单例redis
     */
    @Test
    public void testRedisSingleMachine(){
        Jedis jedis = new Jedis("192.168.181.129" , 6379);
        jedis.set("name" ,"zhangsan");
        String res = jedis.get("name");
        System.out.println("res: "+ res );
    }

    /**
     * 测试redis线程池
     */
    @Test
    public void testRedisPool(){
        JedisPoolConfig  poolConfig = new JedisPoolConfig();
        poolConfig.setMaxIdle(10);
        poolConfig.setMaxTotal(15);
        poolConfig.setMinIdle(3);
        Jedis jedis = new JedisPool(poolConfig , "192.168.181.129" , 6379).getResource();
        jedis.set("age" , "29");
        String res = jedis.get("age");
        System.out.println("res: "+ res );
    }

    /**
     * 测试redis集群
     */
    public void testRedisCluster(){
        Set <HostAndPort> set = new HashSet<HostAndPort>();
        HostAndPort  hostAndPort001 = new HostAndPort("192.168.181.129" , 7001);
        HostAndPort  hostAndPort002 = new HostAndPort("192.168.181.129" , 7002);
        HostAndPort  hostAndPort003 = new HostAndPort("192.168.181.129" , 7003);
        HostAndPort  hostAndPort004 = new HostAndPort("192.168.181.129" , 7004);
        HostAndPort  hostAndPort005 = new HostAndPort("192.168.181.129" , 7005);
        HostAndPort  hostAndPort006 = new HostAndPort("192.168.181.129" , 7006);
        set.add(hostAndPort001);
        set.add(hostAndPort002);
        set.add(hostAndPort003);
        set.add(hostAndPort004);
        set.add(hostAndPort005);
        set.add(hostAndPort006);

    }
}
